package com.terrace.core.spring.ehcache.interceptor;

import java.io.Serializable;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * 缓存拦截器
 * @author jiangyg
 *
 */
public class EhCacheInterceptor extends EhCacheAspectSupport implements MethodInterceptor, Serializable {

	private static final long serialVersionUID = -950002221580059983L;

	@Override
	public Object invoke(final MethodInvocation invocation) throws Throwable {
		
		EhCacheInvoker cacheInvoker = new EhCacheInvoker() {
			
			@Override
			public Object invoke() throws EhCacheThrowableWrapper {
				try {
					return invocation.proceed();
				} catch (Throwable ex) {
					throw new EhCacheThrowableWrapper(ex);
				}
			}
			
		};
		
		return execute(cacheInvoker, invocation.getThis(), invocation.getMethod(), invocation.getArguments());
	}

}
